﻿
@{
    ViewData["Title"] = "AddLoading";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>住宿设置</h1>
<div id="Lodging" style="width:100%">
     <form class="layui-form" action="" >
          <h2>基本信息</h2>
        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label" style="width:20%">住宿ID</label>
            <div class="layui-input-block">
                <input style="width:20%" type="text" id="lodgingId" name="lodgingId" placeholder="最多预约订单数" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width:100%">
            <label class="layui-form-label" style="width:20%">最晚预定时间:</label>
            <div class="layui-input-inline">
                <select name="interest" lay-filter="aihao">
                    <option value=1>次日</option>
                    <option value=2 selected>今日</option>
                </select>
            </div>

            <div>
                <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="scheduledTime" id="scheduledTime" placeholder="yyyy-MM-dd HH:mm:ss">
                </div>
                <span style="text-align: center;">超过该时间，客户不能预定当前房间</span>
            </div> 
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">最多可预定数:</label>
                <div class="layui-input-block">
                <input style="width:20%" type="text" id="scheduledPeople" name="scheduledPeople" lay-verify="required" placeholder="最多预约订单数"  class="layui-input">
                </div>
            </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">最多可预定天数:</label>
            <div class="layui-input-block">
                <input style="width:20%" type="text" id="scheduledDay" name="scheduledDay" lay-verify="required" placeholder="最多可预约房晚1-60"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">预定日期范围:</label>
            <div class="layui-input-block">
                <input style="width:20%" type="text" id="dateRange" name="dateRange" lay-verify="required" placeholder="订房日期范围1-85天"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">预定须知:</label>
            <div class="layui-input-block">
                <textarea style="width:30%;height:30%" id="scheduledNotice" name="scheduledNotice" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">预定须知确认:</label>
            <div class="layui-input-block">
                <input type="radio" id="noticeConfirm" name="noticeConfirm" value="false" title="关闭" checked>
                <input type="radio" id="noticeConfirm" name="noticeConfirm" value="true" title="启用"> 启用后，订单提交前,会弹窗告知用户 需要用户手动确认
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width:20%">预留信息:</label>
            <div class="layui-input-block">
                <input type="checkbox" name="isReserve" id="isReserve" lay-skin="switch" lay-filter="switchTest" title="true|false">启用后，订单提交前,会弹窗告知用户 需要用户手动确认
            </div>
        </div>
        @* <button type="button"  class="layui-btn" lay-submit lay-filter="submitForm">保存</button> *@
        <div class="layui-form-item">
            <div style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit lay-filter="EditForm">保存</button>
            </div>
        </div>
            </form>
</div>
<script>
    layui.use(['laydate', 'table', 'jquery', 'layer', 'form', 'laypage'], function () {
        var laydate = layui.laydate;
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var laypage = layui.laypage;
        var element = layui.element;
        // 时间选择器
        laydate.render({
            elem: '#ID-laydate-format-4',
            type: 'time',
            format: 'H点m分'
        });

        $.ajax({
            url: 'http://localhost:5174/api/RoomType/GetLodgings', // 替换为实际获取数据的接口 URL
            type: 'get',
            data: {id:4},
            success: function (data) {
                // 假设返回的数据格式为 { "name": "张三", "age": 25 }
                document.getElementById('scheduledTime').value = data.data.scheduledTime;
                document.getElementById('scheduledPeople').value = data.data.scheduledPeople;
                document.getElementById('scheduledDay').value = data.data.scheduledDay;
                document.getElementById('dateRange').value = data.data.dateRange;
                document.getElementById('scheduledNotice').value = data.data.scheduledNotice;
                document.getElementById('noticeConfirm').value = data.data.noticeConfirm;
                document.getElementById('isReserve').value = data.data.isReserve;
            },
            error: function () {
                console.error('获取反填数据失败');
            }
        });

        form.on('submit(EditForm)', function (data) {
            data.elem.disabled = true;//防止重复提交
            if (data.field.isReserve = "on") {
                data.field.isReserve = 1;
            }
            else {
                data.field.isReserve = 0;
            }
            if (data.field.noticeConfirm == true) {
                data.field.noticeConfirm = 1;
            }
            else {
                data.field.noticeConfirm = 0;
            }
            data.field.lodgingId = 4;
            $.ajax({
                url: 'http://localhost:5174/api/RoomType/UpdateLoading',
                type: 'post',
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (res) {
                    // 添加成功后的操作
                    if (res.code > 0) {
                        layer.msg("保存成功");
                       
                    }
                }
            });
            return false;
        })
        // form.on('submit(submitForm)', function (data) {
        //     if (data.field.isReserve ="on") {
        //         data.field.isReserve = 1;
        //     }
        //     else
        //     {
        //         data.field.isReserve = 0;
        //     }
        //     if (data.field.noticeConfirm == true) {
        //         data.field.noticeConfirm = 1;
        //     }
        //     else { 
        //         data.field.noticeConfirm = 0;
        //     }
        //     console.log(data.field)
        //     data.elem.disabled = true;//防止重复提交
        //     $.ajax({
        //         url: 'http://localhost:5174/api/RoomType/AddLoading',
        //         type: 'post',
        //         contentType: "application/json",
        //         data: JSON.stringify(data.field),
        //         success: function (res) {
        //             // 添加成功后的操作
        //             if (res.code > 0) {
        //                 layer.msg("添加成功");
        //                 show()
        //             }
        //         }
        //     });
        //     return false;
        //     console.log(data.field);
        // });
        // 日期时间选择器 - 日期和时间选择器同时显示（全面板）
        laydate.render({
            elem: '#scheduledTime',
            type: 'datetime',
            fullPanel: true // 2.8+
        });
    })
</script>
